// columns.ts

import DictTag, { DictValueEnum } from "@/components/DictTag";
import { createIcon } from "@/utils/IconUtil";
import { ProColumns } from "@ant-design/pro-table";
import { Divider, Popconfirm, Space, Switch, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	statusOptions: DictValueEnum,
	handleColumnEditor: (record: API.Setting.PostVo) => void,
	handleColumnRemove: (record: API.Setting.PostVo) => void
): ProColumns<API.Setting.PostVo>[] => {
	return [
		{
			title: "职位名称",
			dataIndex: "name",
			valueType: "text"
		},
		{
			title: "职位编码",
			dataIndex: "code",
			valueType: "text"
		},
		{
			title: "显示顺序",
			dataIndex: "sort",
			valueType: "digit",
			width: "lg",
			hideInSearch: true,
			sorter: (a, b) => a.sort - b.sort
		},
		{
			title: "状态",
			dataIndex: "status",
			valueType: "select",
			valueEnum: statusOptions,
			render: (_, record) => {
				return <DictTag type="badge" enums={statusOptions} value={record.status} />;
			}
		},
		{
			title: "创建时间",
			key: "noSearch",
			dataIndex: "createTime",
			valueType: "dateTime",
			hideInSearch: true,
			width: "lg"
		},
		{
			title: "创建时间",
			key: "Search",
			dataIndex: "createTime",
			valueType: "dateRange",
			hideInTable: true,
			width: "lg",
			// hideInSearch: false,
			search: {
				transform: value => {
					return {
						beginTime: value[0],
						endTime: value[1]
					};
				}
			}
		},
		{
			title: "操作",
			dataIndex: "option",
			width: "220px",
			valueType: "option",
			fixed: "right",
			render: (_, record: any) => {
				return (
					<>
						<Space size={2} split={<Divider type="vertical" />}>
							<Typography.Link
								key="edit"
								onClick={() => {
									handleColumnEditor(record);
								}}
							>
								编辑
							</Typography.Link>
							<Popconfirm
								placement="bottomRight"
								title="提示"
								description={`确认要删除职位名称为: ${record.name} 的职位吗？`}
								onConfirm={async () => handleColumnRemove(record)}
								okText="确认"
								cancelText="取消"
							>
								<Typography.Link type="danger" key="remove">
									删除
								</Typography.Link>
							</Popconfirm>
						</Space>
					</>
				);
			}
		}
	];
};

export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const pagination = {
	showQuickJumper: true,
	showSizeChanger: true
};

export const formTitle = ["创建职位", "修改职位"];
